package com.sg.service.biz.component.impl;

import com.sg.common.util.RedisUtil;
import com.sg.dto.biz.component.req.GenerateCycleUpdateSliceComReqDto;
import com.sg.dto.biz.component.req.GenerateSemanticInstanceStoryComReqDto;
import com.sg.dto.biz.component.req.ImplementTimeTurnToStringComReqDto;
import com.sg.dto.biz.component.res.GenerateCycleUpdateSliceComRespDto;
import com.sg.dto.biz.component.res.GenerateSemanticInstanceStoryComRespDto;
import com.sg.dto.biz.component.res.ImplementTimeTurnToStringComRespDto;
import com.sg.service.biz.component.InterfaceModeService;
import com.sg.service.biz.component.TemplateEngineService;
import com.sg.common.exception.Assert;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author ：
 * @version 1.0
 * @date ：
 */
@Service
public class CycleStageDataServiceImpl
        implements com.wicket.okrcomponent.biz.service.CycleStageDataService {

    @Resource
    private RedisUtil redisUtil;
    @Resource
    private InterfaceModeService interfaceModeService;
    @Resource
    private TemplateEngineService templateEngineService;

    /**
     * D2生成周期更新切片(公共)[8571]
     * gen by moon at 4/10/2024, 6:53:36 PM
     */
    @Trace(operationName = "D2生成周期更新切片(公共)")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    @Transactional(rollbackFor = Exception.class)
    @Override
    public GenerateCycleUpdateSliceComRespDto generateCycleUpdateSliceCom(GenerateCycleUpdateSliceComReqDto reqDto) {


        GenerateSemanticInstanceStoryComRespDto generateSemanticInstanceStoryComRespDto_1 = null;
        //virtualUsage D2-执行标准时间转换为字符串(公共)  62343
        ImplementTimeTurnToStringComRespDto implementTimeTurnToStringComRespDto = null;
        ImplementTimeTurnToStringComReqDto implementTimeTurnToStringComReqDto = new ImplementTimeTurnToStringComReqDto();
        if (reqDto != null) {
            implementTimeTurnToStringComReqDto.setComTimeField(reqDto.getCycleStartTime());//SimpleFieldAssign//sourceId:1574107_1_62343
        }

        /*D2-执行标准时间转换为字符串(公共)[6274]   */
        Assert.isNull(implementTimeTurnToStringComReqDto.getComTimeField(), "D2生成周期更新切片(公共)-D2-执行标准时间转换为字符串(公共)-通用时间字段不能为空", false);
        implementTimeTurnToStringComRespDto = interfaceModeService.implementTimeTurnToStringCom(implementTimeTurnToStringComReqDto)/*vcase invoke isSameApp*/;


//virtualUsage D2-执行标准时间转换为字符串(公共)  62344
        ImplementTimeTurnToStringComRespDto implementTimeTurnToStringComRespDto_2 = null;
        ImplementTimeTurnToStringComReqDto implementTimeTurnToStringComReqDto_1 = new ImplementTimeTurnToStringComReqDto();
        if (reqDto != null) {
            implementTimeTurnToStringComReqDto_1.setComTimeField(reqDto.getCycleEndTime());//SimpleFieldAssign//sourceId:1574107_1_62344
        }

        /*D2-执行标准时间转换为字符串(公共)[6274]   */
        Assert.isNull(implementTimeTurnToStringComReqDto_1.getComTimeField(), "D2生成周期更新切片(公共)-D2-执行标准时间转换为字符串(公共)-通用时间字段不能为空", false);
        implementTimeTurnToStringComRespDto_2 = interfaceModeService.implementTimeTurnToStringCom(implementTimeTurnToStringComReqDto_1)/*vcase invoke isSameApp*/;


//virtualUsage D2生成周期更新切片(公共)  62345
        GenerateSemanticInstanceStoryComRespDto generateSemanticInstanceStoryComRespDto = null;
        if (implementTimeTurnToStringComRespDto != null && implementTimeTurnToStringComRespDto_2 != null) {
            GenerateSemanticInstanceStoryComReqDto generateSemanticInstanceStoryComReqDto = new GenerateSemanticInstanceStoryComReqDto();
            generateSemanticInstanceStoryComReqDto.setTemplateSemanticEngineCode("WORK_CYCLE_UPDATE_SLICE");//CUSTOM_CONVENTION//sourceId:1574105_1_62345
            generateSemanticInstanceStoryComReqDto.setFirstFieldName("parentSubMidCycleType");//CUSTOM_CONVENTION//sourceId:1574099_1_62345
            generateSemanticInstanceStoryComReqDto.setSecondFieldName("cycleStartTime");//CUSTOM_CONVENTION//sourceId:1574101_1_62345
            generateSemanticInstanceStoryComReqDto.setThirdFieldName("cycleEndTime");//CUSTOM_CONVENTION//sourceId:1574103_1_62345
            generateSemanticInstanceStoryComReqDto.setFourFieldName("evaObjTargetCycleId");//CUSTOM_CONVENTION//sourceId:1574132_1_62345
            if (reqDto != null) {
                generateSemanticInstanceStoryComReqDto.setFirstFieldValue(reqDto.getParentSubMidCycleType());//SimpleFieldAssign//sourceId:1574100_1_62345
                generateSemanticInstanceStoryComReqDto.setFourFieldValue(reqDto.getEvaObjTargetCycleId());//SimpleFieldAssign//sourceId:1574133_1_62345
            }
            if (implementTimeTurnToStringComRespDto != null) {
                generateSemanticInstanceStoryComReqDto.setSecondFieldValue(implementTimeTurnToStringComRespDto.getComTxtField());//SimpleFieldAssign//sourceId:1574102_1_62345
            }
            if (implementTimeTurnToStringComRespDto_2 != null) {
                generateSemanticInstanceStoryComReqDto.setThirdFieldValue(implementTimeTurnToStringComRespDto_2.getComTxtField());//SimpleFieldAssign//sourceId:1574104_1_62345
            }

            /*D2生成周期更新切片(公共)[8234]   */
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getTemplateSemanticEngineCode(), "D2生成周期更新切片(公共)-D2生成周期更新切片(公共)-模板引擎标识不能为空", false);
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getFirstFieldName(), "D2生成周期更新切片(公共)-D2生成周期更新切片(公共)-第一个字段字段名不能为空", false);
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getFirstFieldValue(), "D2生成周期更新切片(公共)-D2生成周期更新切片(公共)-第一个字段字段值不能为空", false);
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getSecondFieldName(), "D2生成周期更新切片(公共)-D2生成周期更新切片(公共)-第二个字段字段名不能为空", false);
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getSecondFieldValue(), "D2生成周期更新切片(公共)-D2生成周期更新切片(公共)-第二个字段字段值不能为空", false);
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getThirdFieldName(), "D2生成周期更新切片(公共)-D2生成周期更新切片(公共)-第三个字段字段名不能为空", false);
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getThirdFieldValue(), "D2生成周期更新切片(公共)-D2生成周期更新切片(公共)-第三个字段字段值不能为空", false);
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getFourFieldName(), "D2生成周期更新切片(公共)-D2生成周期更新切片(公共)-第四个字段字段名不能为空", false);
            Assert.isNull(generateSemanticInstanceStoryComReqDto.getFourFieldValue(), "D2生成周期更新切片(公共)-D2生成周期更新切片(公共)-第四个字段字段值不能为空", false);
            generateSemanticInstanceStoryComRespDto = templateEngineService.generateSemanticInstanceStoryCom(generateSemanticInstanceStoryComReqDto)/*vcase invoke isSameApp*/;


            generateSemanticInstanceStoryComRespDto_1 = generateSemanticInstanceStoryComRespDto;
        }
        GenerateCycleUpdateSliceComRespDto retData = new GenerateCycleUpdateSliceComRespDto();
        if (generateSemanticInstanceStoryComRespDto_1 != null) {
            retData.setObjectName(generateSemanticInstanceStoryComRespDto_1.getObjectName());//SimpleFieldAssign//sourceId:1591073_1
        }


        return retData;
    }
    //
}
